package com.sinopec.basemodule.launchcontract

import android.content.Intent
import android.os.Parcelable

/**
 * create by lwj at 2023/4/12
 * 核心 getset设置
 */
interface GetSetFromIntent<T> {
    fun get(intent: Intent?): T?
    fun set(t: T?, intent: Intent)

    object Unit : GetSetFromIntent<kotlin.Unit> {
        override fun get(intent: Intent?) {
        }

        override fun set(t: kotlin.Unit?, intent: Intent) {
        }
    }

    object Int : GetSetFromIntent<kotlin.Int> {
        override fun get(intent: Intent?): kotlin.Int? {
            return intent?.getIntExtra("params", -1)
        }

        override fun set(t: kotlin.Int?, intent: Intent) {
            intent.putExtra("params", t!!)
        }

    }

    object String : GetSetFromIntent<kotlin.String> {
        override fun get(intent: Intent?): kotlin.String? {
            return intent?.getStringExtra("params")
        }

        override fun set(t: kotlin.String?, intent: Intent) {
            intent.putExtra("params", t!!)
        }
    }

    object Boolean : GetSetFromIntent<kotlin.Boolean> {
        override fun get(intent: Intent?): kotlin.Boolean? {
            return intent?.getBooleanExtra("params", false) ?: false
        }

        override fun set(t: kotlin.Boolean?, intent: Intent) {
            intent.putExtra("params", t ?: false)
        }
    }

    class Parcelables<T : Parcelable> : GetSetFromIntent<T> {
        override fun get(intent: Intent?): T? {
            return intent?.getParcelableExtra("params")
        }

        override fun set(t: T?, intent: Intent) {
            intent.putExtra("params", t)
        }
    }


}